home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 July: Mac OS SDK / Dev.CD Jul 00 SDK2.toast / Development Kits / Cross Platform / QuickTime 4.1.2 Windows SDK / CIncludes / fenv.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-04-12  |  11.5 KB  |  304 lines  |  [TEXT/R*ch]

  1. /*
  2.      File:        fenv.h
  3.  
  4.      Contains:    Floating-Point environment for PowerPC and 68K
  5.  
  6.      Version:    Technology:    MathLib v2
  7.                  Release:    QuickTime 4.1
  8.  
  9.      Copyright:    (c) 1987-1999 by Apple Computer, Inc., all rights reserved.
  10.  
  11.      Bugs?:        For bug reports, consult the following page on
  12.                  the World Wide Web:
  13.  
  14.                      http://developer.apple.com/bugreporter/
  15.  
  16. */
  17. #ifndef __FENV__
  18. #define __FENV__
  19.  
  20. #ifndef __CONDITIONALMACROS__
  21.     #include <ConditionalMacros.h>
  22. #endif
  23.  
  24.  
  25.  
  26.  
  27. #if PRAGMA_ONCE
  28. #pragma once
  29. #endif
  30.  
  31. #ifdef __cplusplus
  32. extern "C" {
  33. #endif
  34.  
  35. #if PRAGMA_IMPORT
  36. #pragma import on
  37. #endif
  38.  
  39. #if PRAGMA_STRUCT_ALIGN
  40.     #pragma options align=mac68k
  41. #elif PRAGMA_STRUCT_PACKPUSH
  42.     #pragma pack(push, 2)
  43. #elif PRAGMA_STRUCT_PACK
  44.     #pragma pack(2)
  45. #endif
  46.  
  47. #if TARGET_OS_MAC
  48. /*
  49.     A collection of functions designed to provide access to the floating
  50.     point environment for numerical programming. It is modeled after
  51.     the floating-point requirements in C9X.
  52.     
  53.     The file <fenv.h> declares many functions in support of numerical
  54.     programming.  It provides a set of environmental controls similar to
  55.     the ones found in <SANE.h>.  Programs that test flags or run under
  56.     non-default modes must do so under the effect of an enabling
  57.     "fenv_access" pragma.
  58. */
  59.  
  60. /********************************************************************************
  61. *                                                                                *
  62. *    fenv_t         is a type for representing the entire floating-point        *
  63. *                     environment in a single object.                              *
  64. *                                                                                *
  65. *     fexcept_t        is a type for representing the floating-point                *
  66. *                     exception flag state collectively.                           *
  67. *                                                                                *
  68. ********************************************************************************/
  69. #if TARGET_CPU_PPC
  70. typedef long                             fenv_t;
  71. typedef long                             fexcept_t;
  72. /*    Definitions of floating-point exception macros                          */
  73. enum {
  74.     FE_INEXACT                    = 0x02000000,
  75.     FE_DIVBYZERO                = 0x04000000,
  76.     FE_UNDERFLOW                = 0x08000000,
  77.     FE_OVERFLOW                    = 0x10000000,
  78.     FE_INVALID                    = 0x20000000
  79. };
  80.  
  81.  
  82. /*    Definitions of rounding direction macros                                */
  83. enum {
  84.     FE_TONEAREST                = 0x00000000,
  85.     FE_TOWARDZERO                = 0x00000001,
  86.     FE_UPWARD                    = 0x00000002,
  87.     FE_DOWNWARD                    = 0x00000003
  88. };
  89.  
  90. #endif  /* TARGET_CPU_PPC */
  91.  
  92. #if TARGET_CPU_68K
  93. #if TARGET_RT_MAC_68881
  94. typedef long                             fexcept_t;
  95.  
  96. struct fenv_t {
  97.     long                             FPCR;
  98.     long                             FPSR;
  99. };
  100. typedef struct fenv_t                    fenv_t;
  101. enum {
  102.     FE_INEXACT                    = 0x00000008,                    /* ((long)(8))   */
  103.     FE_DIVBYZERO                = 0x00000010,                    /* ((long)(16))  */
  104.     FE_UNDERFLOW                = 0x00000020,                    /* ((long)(32))  */
  105.     FE_OVERFLOW                    = 0x00000040,                    /* ((long)(64))  */
  106.     FE_INVALID                    = 0x00000080                    /* ((long)(128)) */
  107. };
  108.  
  109. #else
  110.  
  111. typedef short                             fexcept_t;
  112. typedef short                             fenv_t;
  113. enum {
  114.     FE_INVALID                    = 0x0001,                        /* ((short)(1))  */
  115.     FE_UNDERFLOW                = 0x0002,                        /* ((short)(2))  */
  116.     FE_OVERFLOW                    = 0x0004,                        /* ((short)(4))  */
  117.     FE_DIVBYZERO                = 0x0008,                        /* ((short)(8))  */
  118.     FE_INEXACT                    = 0x0010                        /* ((short)(16)) */
  119. };
  120.  
  121. #endif  /* TARGET_RT_MAC_68881 */
  122.  
  123. enum {
  124.     FE_TONEAREST                = 0x0000,                        /* ((short)(0))  */
  125.     FE_UPWARD                    = 0x0001,                        /* ((short)(1))  */
  126.     FE_DOWNWARD                    = 0x0002,                        /* ((short)(2))  */
  127.     FE_TOWARDZERO                = 0x0003                        /* ((short)(3))  */
  128. };
  129.  
  130. /*    Definitions of rounding precision macros  (68K only)                    */
  131. enum {
  132.     FE_LDBLPREC                    = 0x0000,                        /* ((short)(0))  */
  133.     FE_DBLPREC                    = 0x0001,                        /* ((short)(1))  */
  134.     FE_FLTPREC                    = 0x0002                        /* ((short)(2))  */
  135. };
  136.  
  137. #endif  /* TARGET_CPU_68K */
  138.  
  139. /*    The bitwise OR of all exception macros                                  */
  140.  
  141. #define      FE_ALL_EXCEPT     ( FE_INEXACT | FE_DIVBYZERO | FE_UNDERFLOW | FE_OVERFLOW | FE_INVALID )
  142. /*    Definition of pointer to IEEE default environment object                */
  143. extern fenv_t _FE_DFL_ENV;               /* default environment object        */
  144. #define FE_DFL_ENV &_FE_DFL_ENV          /* pointer to default environment    */
  145.  
  146. /*******************************************************************************
  147. *     The following functions provide access to the exception flags.  The      *
  148. *     "int" input argument can be constructed by bitwise ORs of the exception  *
  149. *     macros: for example: FE_OVERFLOW | FE_INEXACT.                           *
  150. *******************************************************************************/
  151. /*******************************************************************************
  152. *     The function "feclearexcept" clears the supported exceptions represented *
  153. *     by its argument.                                                         *
  154. *******************************************************************************/
  155. EXTERN_API_C( void ) feclearexcept(int excepts);
  156.  
  157.  
  158.  
  159. /*******************************************************************************
  160. *    The function "fegetexcept" stores a representation of the exception       *
  161. *     flags indicated by the argument "excepts" through the pointer argument   *
  162. *     "flagp".                                                                 *
  163. *******************************************************************************/
  164. EXTERN_API_C( void ) fegetexcept(fexcept_t *flagp, int excepts);
  165.  
  166.  
  167.  
  168. /*******************************************************************************
  169. *     The function "feraiseexcept" raises the supported exceptions             *
  170. *     represented by its argument.                                             *
  171. *******************************************************************************/
  172. EXTERN_API_C( void ) feraiseexcept(int excepts);
  173.  
  174.  
  175.  
  176. /*******************************************************************************
  177. *     The function "fesetexcept" sets or clears the exception flags indicated  *
  178. *     by the int argument "excepts" according to the representation in the     *
  179. *     object pointed to by the pointer argument "flagp".  The value of         *
  180. *     "*flagp" must have been set by a previous call to "fegetexcept".         *
  181. *     This function does not raise exceptions; it just sets the state of       *
  182. *     the flags.                                                               *
  183. *******************************************************************************/
  184. EXTERN_API_C( void ) fesetexcept(const fexcept_t *flagp, int excepts);
  185.  
  186.  
  187.  
  188. /*******************************************************************************
  189. *     The function "fetestexcept" determines which of the specified subset of  *
  190. *     the exception flags are currently set.  The argument "excepts" specifies *
  191. *     the exception flags to be queried as a bitwise OR of the exception       *
  192. *     macros.  This function returns the bitwise OR of the exception macros    *
  193. *     corresponding to the currently set exceptions included in "excepts".     *
  194. *******************************************************************************/
  195. EXTERN_API_C( int ) fetestexcept(int excepts);
  196.  
  197.  
  198.  
  199. /*******************************************************************************
  200. *     The following functions provide control of rounding direction modes.     *
  201. *******************************************************************************/
  202. /*******************************************************************************
  203. *     The function "fegetround" returns the value of the rounding direction    *
  204. *     macro which represents the current rounding direction.                   *
  205. *******************************************************************************/
  206. EXTERN_API_C( int ) fegetround(void );
  207.  
  208.  
  209.  
  210. /*******************************************************************************
  211. *     The function "fesetround" establishes the rounding direction represented *
  212. *     by its argument.  It returns nonzero if and only if the argument matches *
  213. *     a rounding direction macro.  If not, the rounding direction is not       *
  214. *     changed.                                                                 *
  215. *******************************************************************************/
  216. EXTERN_API_C( int ) fesetround(int round);
  217.  
  218.  
  219.  
  220. /*******************************************************************************
  221. *    The following functions manage the floating-point environment, exception  *
  222. *    flags and dynamic modes, as one entity.                                   *
  223. *******************************************************************************/
  224. /*******************************************************************************
  225. *     The function "fegetenv" stores the current floating-point environment    *
  226. *     in the object pointed to by its pointer argument "envp".                 *
  227. *******************************************************************************/
  228. EXTERN_API_C( void ) fegetenv(fenv_t *envp);
  229.  
  230.  
  231.  
  232. /*******************************************************************************
  233. *     The function "feholdexcept" saves the current environment in the object  *
  234. *     pointed to by its pointer argument "envp", clears the exception flags,   *
  235. *     and clears floating-point exception enables.  This function supersedes   *
  236. *     the SANE function "procentry", but it does not change the current        *
  237. *     rounding direction mode.                                                 *
  238. *******************************************************************************/
  239. EXTERN_API_C( int ) feholdexcept(fenv_t *envp);
  240.  
  241.  
  242.  
  243. /*******************************************************************************
  244. *     The function "fesetenv" installs the floating-point environment          *
  245. *     environment represented by the object pointed to by its argument         *
  246. *     "envp".  The value of "*envp" must be set by a call to "fegetenv" or     *
  247. *     "feholdexcept", by an implementation-defined macro of type "fenv_t",     *
  248. *     or by the use of the pointer macro FE_DFL_ENV as the argument.           *
  249. *******************************************************************************/
  250. EXTERN_API_C( void ) fesetenv(const fenv_t *envp);
  251.  
  252.  
  253.  
  254. /*******************************************************************************
  255. *     The function "feupdateenv" saves the current exceptions into its         *
  256. *     automatic storage, installs the environment represented through its      *
  257. *     pointer argument "envp", and then re-raises the saved exceptions.        *
  258. *     This function, which supersedes the SANE function "procexit", can be     *
  259. *     used in conjunction with "feholdexcept" to write routines which hide     *
  260. *     spurious exceptions from their callers.                                  *
  261. *******************************************************************************/
  262. EXTERN_API_C( void ) feupdateenv(const fenv_t *envp);
  263.  
  264.  
  265.  
  266. #if TARGET_CPU_68K
  267. /*******************************************************************************
  268. *     The following functions provide control of rounding precision.           *
  269. *     Because the PowerPC does not provide this capability, these functions    *  
  270. *     are available only for the 68K Macintosh.  Rounding precision values     *
  271. *     are defined by the rounding precision macros.  These functions are       *
  272. *     equivalent to the SANE functions getprecision and setprecision.          *
  273. *******************************************************************************/
  274. EXTERN_API_C( int ) fegetprec(void );
  275.  
  276. EXTERN_API_C( int ) fesetprec(int precision);
  277.  
  278. #endif  /* TARGET_CPU_68K */
  279.  
  280. #endif  /* TARGET_OS_MAC */
  281.  
  282.  
  283.  
  284. #if PRAGMA_STRUCT_ALIGN
  285.     #pragma options align=reset
  286. #elif PRAGMA_STRUCT_PACKPUSH
  287.     #pragma pack(pop)
  288. #elif PRAGMA_STRUCT_PACK
  289.     #pragma pack()
  290. #endif
  291.  
  292. #ifdef PRAGMA_IMPORT_OFF
  293. #pragma import off
  294. #elif PRAGMA_IMPORT
  295. #pragma import reset
  296. #endif
  297.  
  298. #ifdef __cplusplus
  299. }
  300. #endif
  301.  
  302. #endif /* __FENV__ */
  303.  
  304.